package com.tjbank.cssys.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkStopNoticePerson;
import com.tjbank.cssys.repository.CkStopNoticePersonMapper;
import com.tjbank.cssys.web.service.CkStopNoticePersonService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class CkStopNoticePersonServiceImpl implements CkStopNoticePersonService {

    protected static final Logger logger = LoggerFactory.getLogger(CkStopNoticePersonServiceImpl.class);

    @Autowired
    private CkStopNoticePersonMapper stopNoticePersonMapper;

    @Override
    public PageInfo selectList(Map<String, Object> params) {
        logger.info("名单库查询   params=="+JSON.toJSONString(params));
        int page = Integer.parseInt(params.getOrDefault("page", "1").toString());
        int pageSize = Integer.parseInt(params.getOrDefault("pageSize", "10").toString());
        PageHelper.startPage(page, pageSize);
        List<CkStopNoticePerson> datas = stopNoticePersonMapper.selectList(params);

        PageInfo result = new PageInfo(datas);
        logger.info("名单库查询   结果=="+JSON.toJSONString(result));
        return result;
    }

    @Override
    public void deleteById(Long Id) {
        stopNoticePersonMapper.deleteByPrimaryKey(Id);
    }

    @Override
    public void deleteByIds(String Ids) {
        if(StringUtils.isNotBlank(Ids)){
            logger.info("逻辑删除名单   params Ids=="+Ids);
            String[] split = Ids.split(",");
            for(int i=0;i<split.length;i++){
                String tt = split[i];
                Long id = Long.parseLong(tt);
                if(null!=id){
                    CkStopNoticePerson ckStopNoticePerson = stopNoticePersonMapper.selectByPrimaryKey(id);
                    ckStopNoticePerson.setIsDelete((byte) 1);
                    stopNoticePersonMapper.updateByPrimaryKey(ckStopNoticePerson);
                }
            }

        }

    }

    @Override
    public boolean insert(CkStopNoticePerson record) {
        int insert = stopNoticePersonMapper.insert(record);
        if(insert==1){
            return true;
        }else{
            return false;
        }

    }

    @Override
    public void updateType(String ids,Byte t_type) {
        if(StringUtils.isNotBlank(ids)) {
            String[] split = ids.split(",");
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("type",t_type);
            params.put("ids",split);

            logger.info("将停催置为失联，参数：params="+ JSON.toJSONString(params));
            stopNoticePersonMapper.updateType(split,t_type);
        }
    }

    @Override
    public List<CkStopNoticePerson> findOutOfContactAll() {
      return   stopNoticePersonMapper.findOutOfContactAll();

    }

    @Override
    public void updateForeach(List<CkStopNoticePerson> contactCkStopNoticePeople) {
           stopNoticePersonMapper.updateForeach(contactCkStopNoticePeople);
    }

    @Override
    public List<String> findOutOfContactBySerialNumber(Set<String> serialNumbers) {
        List<String> serialNumberList = new ArrayList<>();
        serialNumbers.stream().forEach(s -> serialNumberList.add(s));
        return stopNoticePersonMapper.findOutOfContactBySerialNumber(serialNumberList);
    }

    @Override
    public void insertForeach(List<CkStopNoticePerson> ckStopNoticePeople2) {
        stopNoticePersonMapper.insertForeach(ckStopNoticePeople2);
    }




}
